use std::fs;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::prelude::*;
/// file opeate test
const FILE_NAME: &str = "./src/file_t/a.txt";

pub fn create_file() -> std::io::Result<()>{
    File::create(FILE_NAME)?;
    Ok(())
}

pub fn write_file() -> std::io::Result<()> {
    fs::write(FILE_NAME, b"Lorem ipsum")?;
    fs::write(FILE_NAME, "dolor sit")?;
    Ok(())
}

pub fn read_file()-> std::io::Result<()>  {
    let contents = fs::read_to_string(FILE_NAME)?;
    println!("{}", contents);
    Ok(())
}
pub fn write_append_file()->std::io::Result<()>{
    let mut f = OpenOptions::new()
        .create(true)
        .append(true)
        .open(FILE_NAME)?;
    f.write_all(b"sss111\n")?;
    Ok(())
}
pub fn del_file() -> std::io::Result<()> {
    fs::remove_file(FILE_NAME)?;
    Ok(())
}